package xginxnote

import (
	"encoding/json"

	"gitee.com/xiaoyutab/xgotool/optional/xnote"
	"gitee.com/xiaoyutab/xgotool/xgin"
	"gitee.com/xiaoyutab/xgotool/xstring"
	"github.com/gin-gonic/gin"
)

// 存储详情数据
//
//	POST	/get.content
func getContent(c *gin.Context) *xgin.Response {
	type fid_struct struct {
		Id json.Number `form:"id" json:"id"` // 笔记ID
	}
	temp := fid_struct{}
	if err := xgin.Bind(c, &temp); err != nil {
		return xgin.Resp().Error(err)
	}
	cn_id := xstring.JUint(temp.Id)
	// 获取详情进行权限检测
	info, err := xnote.GetMenuInfo(cn_id)
	if err != nil {
		return xgin.Resp().Error(err)
	}
	if info.UserId != c.GetUint("uid") || info.Id != cn_id {
		return xgin.Resp().ErrorEmpty()
	}
	// 获取数据结构
	s, err := xnote.GetContent(cn_id)
	if err != nil {
		return xgin.Resp().Error(err)
	}
	return xgin.Resp().Success(gin.H{
		"content": s,
	})
}
